import request from '@/axios'

export const getGeneratePageListApi = (data) => {
  return request.post({ url: '/api/generate/modelPageList', data })
}

export const getGenerateListApi = (data) => {
  return request.post({ url: '/api/generate/modelList', data })
}

export const getModelOptionsApi = (data) => {
  return request.post({ url: '/api/generate/getModelOptions', data })
}

export const selectFieldOptionsApi = (data) => {
  return request.post({ url: '/api/generate/selectFieldOptions', data })
}

export const saveGenerate = (data) => {
  return request.post({ url: '/api/generate/saveModel', data })
}

export const updateGenerate = (data) => {
  return request.post({ url: '/api/generate/updateModel', data })
}

export const importSqlApi = (data) => {
  return request.post({ url: '/api/generate/importSql', data })
}

export const deleteGenerate = (generateId: string) => {
  return request.post({ url: '/api/generate/delModel', data: { id: generateId } })
}

export const selectModelById = (generateId) => {
  return request.post({ url: '/api/generate/selectModelById', data: { id: generateId } })
}

export const checkFieldExistApi = (data) => {
  return request.post({ url: '/api/generate/checkFieldExist', data })
}

export const updateFieldByIdApi = (data) => {
  return request.post({ url: '/api/generate/updateFieldById', data })
}

export const selectModelByTableName = (tableName: string) => {
  return request.post({
    url: '/api/generate/selectModelByTableName',
    data: { tableName: tableName }
  })
}

export const syncDataBase = (generateId: string) => {
  return request.post({ url: '/api/generate/syncDataBase', data: { id: generateId } })
}

export const codeFileGenerator = (data, fileName) => {
  return request.downloadFile({
    url: '/api/generate/codeFileGenerator',
    data,
    downloadFileName: fileName + '.zip'
  })
}
